<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" 
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity6">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>安全认证系统</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link th:href="@{/vendor/bootstrap/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/vendor/bootstrap-icons/font/bootstrap-icons.min.css}" rel="stylesheet">
    <style>
        :root {
            --primary-color: #4e73df;
            --secondary-color: #f8f9fc;
            --accent-color: #4e73df;
            --text-color: #5a5c69;
            --sidebar-width: 250px;
        }
        
        body {
            font-family: 'Noto Sans SC', sans-serif;
            color: var(--text-color);
            background-color: #f8f9fc;
        }
        
        .navbar-brand {
            font-weight: 700;
            font-size: 1.2rem;
        }
        
        .top-navbar {
            background: #fff;
            box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
            border: none;
        }
        
        .sidebar {
            width: var(--sidebar-width);
            background: linear-gradient(180deg, var(--primary-color) 10%, #224abe 100%);
            color: white;
            min-height: 100vh;
            position: fixed;
            left: 0;
            top: 0;
            z-index: 100;
            transition: all 0.3s;
        }
        
        .sidebar-hidden {
            margin-left: calc(-1 * var(--sidebar-width));
        }
        
        .main-content {
            margin-left: var(--sidebar-width);
            padding: 1.5rem;
            transition: all 0.3s;
        }
        
        .main-content-expanded {
            margin-left: 0;
        }
        
        .sidebar-brand {
            height: 70px;
            display: flex;
            align-items: center;
            padding: 0 1.5rem;
            font-size: 1.2rem;
            font-weight: 700;
        }
        
        .sidebar-divider {
            border-top: 1px solid rgba(255, 255, 255, 0.15);
            margin: 0 1rem;
        }
        
        .sidebar-heading {
            text-transform: uppercase;
            font-size: 0.7rem;
            font-weight: 700;
            padding: 1rem;
            color: rgba(255, 255, 255, 0.6);
        }
        
        .sidebar .nav-item {
            position: relative;
        }
        
        .sidebar .nav-item .nav-link {
            color: rgba(255, 255, 255, 0.8);
            padding: 0.75rem 1.5rem;
            font-weight: 500;
            font-size: 0.85rem;
        }
        
        .sidebar .nav-item .nav-link:hover {
            color: #fff;
            background-color: rgba(255, 255, 255, 0.1);
        }
        
        .sidebar .nav-item .nav-link.active {
            color: #fff;
            font-weight: 700;
            background-color: rgba(255, 255, 255, 0.1);
            border-left: 4px solid #fff;
        }
        
        .sidebar .nav-item .nav-link i {
            margin-right: 0.5rem;
            font-size: 1rem;
            width: 1.5rem;
            text-align: center;
        }
        
        .card {
            border: none;
            box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
            border-radius: 0.5rem;
            margin-bottom: 1.5rem;
        }
        
        .card-header {
            font-weight: 700;
            border-bottom: 1px solid #e3e6f0;
            background-color: #f8f9fc;
        }
        
        .btn-primary {
            background-color: var(--primary-color);
            border-color: var(--primary-color);
        }
        
        .btn-primary:hover {
            background-color: #2e59d9;
            border-color: #2e59d9;
        }
        
        .btn-danger {
            background-color: #e74a3b;
            border-color: #e74a3b;
        }
        
        .bg-primary {
            background-color: var(--primary-color) !important;
        }
        
        .bg-success {
            background-color: #1cc88a !important;
        }
        
        .bg-info {
            background-color: #36b9cc !important;
        }
        
        .bg-warning {
            background-color: #f6c23e !important;
        }
        
        .bg-danger {
            background-color: #e74a3b !important;
        }
        
        .page-header {
            margin-bottom: 1.5rem;
        }
        
        .page-header h1 {
            font-weight: 700;
            font-size: 1.75rem;
            color: #333;
        }
        
        footer {
            background-color: #fff;
            border-top: 1px solid #e3e6f0;
            padding: 1.5rem 0;
            margin-top: 3rem;
        }
        
        .dropdown-menu {
            box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
            border: none;
        }
        
        .topbar-divider {
            width: 1px;
            height: 2rem;
            background-color: #e3e6f0;
            margin: 0 0.8rem;
        }
        
        .alert {
            border-radius: 0.5rem;
            border: none;
            box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
        }
        
        .table th {
            font-weight: 700;
            background-color: #f8f9fc;
        }
        
        /* 响应式处理 */
        @media (max-width: 768px) {
            .sidebar {
                margin-left: calc(-1 * var(--sidebar-width));
            }
            
            .sidebar.show {
                margin-left: 0;
            }
            
            .main-content {
                margin-left: 0;
            }
            
            .navbar-brand span {
                display: none;
            }
        }

        .fade-in {
            animation: fadeIn 0.5s ease-in-out;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
    </style>
</head>
<body>
    <!-- 侧边栏 -->
    <nav class="sidebar" id="sidebar" sec:authorize="isAuthenticated()">
        <div class="sidebar-brand">
            <i class="bi bi-shield-lock me-2"></i>
            <span>安全认证系统</span>
        </div>
        
        <hr class="sidebar-divider">
        
        <div class="sidebar-heading">导航</div>
        
        <ul class="nav flex-column">
            <li class="nav-item">
                <a class="nav-link" th:href="@{/home}">
                    <i class="bi bi-house"></i>
                    <span>首页</span>
                </a>
            </li>
            
            <li class="nav-item" sec:authorize="hasRole('USER')">
                <a class="nav-link" th:href="@{/user/dashboard}">
                    <i class="bi bi-speedometer2"></i>
                    <span>用户仪表盘</span>
                </a>
            </li>
            
            <li class="nav-item" sec:authorize="hasRole('USER')">
                <a class="nav-link" th:href="@{/user/profile}">
                    <i class="bi bi-person-circle"></i>
                    <span>个人资料</span>
                </a>
            </li>
            
            <hr class="sidebar-divider">
            
            <div class="sidebar-heading" sec:authorize="hasRole('ADMIN')">管理员</div>
            
            <li class="nav-item" sec:authorize="hasRole('ADMIN')">
                <a class="nav-link" th:href="@{/admin/dashboard}">
                    <i class="bi bi-gear"></i>
                    <span>管理员仪表盘</span>
                </a>
            </li>
            
            <li class="nav-item" sec:authorize="hasRole('ADMIN')">
                <a class="nav-link" th:href="@{/admin/users}">
                    <i class="bi bi-people"></i>
                    <span>用户管理</span>
                </a>
            </li>
        </ul>
        
        <hr class="sidebar-divider">
        
        <div class="sidebar-heading">账户</div>
        
        <ul class="nav flex-column mb-5">
            <li class="nav-item">
                <form th:action="@{/logout}" method="post" class="d-inline w-100">
                    <button type="submit" class="btn nav-link text-left w-100">
                        <i class="bi bi-box-arrow-right"></i>
                        <span>退出登录</span>
                    </button>
                </form>
            </li>
        </ul>
    </nav>

    <!-- 主内容区 -->
    <div class="main-content" id="content" th:classappend="${!#authorization.expression('isAuthenticated()')} ? 'main-content-expanded' : ''">
        <!-- 顶部导航栏 -->
        <nav class="navbar navbar-expand-lg top-navbar mb-4">
            <div class="container-fluid">
                <button id="sidebarToggle" class="btn" sec:authorize="isAuthenticated()">
                    <i class="bi bi-list"></i>
                </button>
                
                <a class="navbar-brand ms-3" href="/">
                    <i class="bi bi-shield-lock me-2"></i>
                    <span>安全认证系统</span>
                </a>
                
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent">
                    <i class="bi bi-three-dots"></i>
                </button>
                
                <div class="collapse navbar-collapse" id="navbarContent">
                    <ul class="navbar-nav ms-auto">
                        <li class="nav-item dropdown" sec:authorize="isAuthenticated()">
                            <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                                <span class="d-none d-lg-inline me-2 text-gray-600">
                                    <i class="bi bi-person-circle me-1"></i>
                                    <span sec:authentication="name"></span>
                                </span>
                            </a>
                            <div class="dropdown-menu dropdown-menu-end shadow animated--grow-in">
                                <a class="dropdown-item" th:href="@{/user/profile}" sec:authorize="hasRole('USER')">
                                    <i class="bi bi-person-circle text-gray-400 me-1"></i>
                                    个人资料
                                </a>
                                <div class="dropdown-divider"></div>
                                <form th:action="@{/logout}" method="post">
                                    <button type="submit" class="dropdown-item">
                                        <i class="bi bi-box-arrow-right text-gray-400 me-1"></i>
                                        退出登录
                                    </button>
                                </form>
                            </div>
                        </li>
                        
                        <li class="nav-item" sec:authorize="!isAuthenticated()">
                            <a class="nav-link" th:href="@{/login}">
                                <i class="bi bi-box-arrow-in-right me-1"></i>登录
                            </a>
                        </li>
                        
                        <li class="nav-item" sec:authorize="!isAuthenticated()">
                            <a class="nav-link" th:href="@{/register}">
                                <i class="bi bi-person-plus me-1"></i>注册
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>

        <div class="container-fluid fade-in">
            <div th:if="${param.error}" class="alert alert-danger">
                <i class="bi bi-exclamation-triangle-fill me-2"></i>登录失败，请检查用户名和密码
            </div>
            <div th:if="${param.logout}" class="alert alert-success">
                <i class="bi bi-check-circle-fill me-2"></i>您已成功退出登录
            </div>
            <div th:if="${param.registered}" class="alert alert-success">
                <i class="bi bi-check-circle-fill me-2"></i>注册成功，请登录
            </div>
            
            <div th:replace="${content}">
                <!-- 页面内容将插入此处 -->
            </div>
        </div>
        
        <footer>
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-6">
                        <p class="mb-0">© 2025 安全认证系统. 保留所有权利。</p>
                    </div>
                    <div class="col-md-6 text-md-end">
                        <a href="https://spring.io/projects/spring-boot" class="text-decoration-none me-3">Spring Boot</a>
                        <a href="https://spring.io/projects/spring-security" class="text-decoration-none me-3">Spring Security</a>
                        <a href="https://www.thymeleaf.org/" class="text-decoration-none">Thymeleaf</a>
                    </div>
                </div>
            </div>
        </footer>
    </div>

    <script th:src="@{/vendor/bootstrap/js/bootstrap.bundle.min.js}"></script>
    <script>
        // 侧边栏切换
        document.getElementById('sidebarToggle').addEventListener('click', function() {
            document.getElementById('sidebar').classList.toggle('sidebar-hidden');
            document.getElementById('content').classList.toggle('main-content-expanded');
        });
        
        // 设置当前活动导航项
        document.addEventListener('DOMContentLoaded', function() {
            const currentPath = window.location.pathname;
            const navLinks = document.querySelectorAll('.sidebar .nav-link');
            
            navLinks.forEach(link => {
                const href = link.getAttribute('href');
                if (href && currentPath.includes(href)) {
                    link.classList.add('active');
                }
            });
        });
    </script>
</body>
</html> 